package auth

import groovy.transform.CompileStatic

class User4Client {

    Client client
    User4Platform.Platform platform
    String code //wechat->openId
    String deviceId //bind user`s device

    Date dateCreated
    Date lastUpdated

    @CompileStatic
    static enum Client {
        FengChao(2), GongFeng(1), Xia(0), XiaoMi(3)

        final int id;

        Client(int id) {
            this.id = id
        }
    }

    static belongsTo = [user4Platform: User4Platform]

    static constraints = {
        client(nullable: false)
        platform(nullable: true)
        user4Platform(nullable: true)
        code(nullable: false, unique: true)
        deviceId(nullable: false)
    }

    static mapping = {
        client enumType: 'identity'
        platform enumType: 'identity'
    }

    def beforeValidate() {
        this.platform = this.user4Platform.platform
    }
}
